Class PSConnectionPool

java.lang.Object
com.seclore.fs.ws.client.pscp.PSConnectionPool
All Implemented Interfaces:
com.seclore.fs.ws.client.exception.WSClientExceptionConstants, com.seclore.fs.ws.client.exception.WSExceptionConstants

public class PSConnectionPool extends Object implements com.seclore.fs.ws.client.exception.WSClientExceptionConstants
This class is a part of WSClient Library. WSClient Library need to be "Initialized" before using this class.
This class represents a single pool of connections with a given server.
The server for now is assumed to be FileSecure Policy Server but it may be extended to other servers in future.
ConnectionPool is designed to hold a pool of HTTP connections with the server.
Whenever a user requests for a connection, the pool returns an authenticated connection.
When the user returns the connection after use, it goes back to the pool.
If there is no available connection in the pool, a new connection is established, user is authenticated on that session and it is then added to the pool.
New connections will keep getting added till the no of connections reach the maximum limit set by the user.
The connection pool takes care of connecting to a failover server (second URL in the list) if the primary URL is not contactible.
It will continue to work with the second URL till that goes down. Then it will move on to the third URL and so on.

The connection pool requires the user to implement certail interfaces for it to function.
ConnectionPoolConfig : Provides various information used to configure the pool.
ServerDetails : This provides details of the server viz. URLs on which the service is available.
ProxyDetails : This provides details of proxy server required to connect to the server.
LoginHandler : This is one of the most important parts. This has implementation of different APIs provided by the service, required to ping the service or authenticate the user etc. There may be different implementations of this for different ways of authentication e.g. End User, Hot Folder Cabinet User etc. Some implementations of this class may be available with this library.

Config Interface encapsulates all the above interfaces.

The class is designed such that user can maintain multiple pools which work independently, although the need for this may not be very common in FileSecure scenarios.
While connecting to the server over HTTPS, the server needs to have a valid 3rd party SSL certificate else Java security handler will throw an exception.
This can be an issue especially in the development / test / demo environments as self signed certificates may be used in these cases.
You can either add the SSL certificate in the JVM's trust store using "keytool" command or you may execute following code once in your program. Please note that this code will change the default JVM behaviour and trust all certificates. -
 TrustManager[] trustAll = new TrustManager[]
 { 
         new javax.net.ssl.X509TrustManager()
         {
                public java.security.cert.X509Certificate[] getAcceptedIssuers()
                {
                        return null;
                }
                public void checkClientTrusted(java.security.cert.X509Certificate[] certs,String authType)
                {
                }
                public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType)
                {
                }
        }
 };
  
 javax.net.ssl.HostnameVerifier myHv = new javax.net.ssl.HostnameVerifier() 
 {
         public boolean verify(String hostName,javax.net.ssl.SSLSession session)
         {
                 return true;
         }
 };
 
 javax.net.ssl.HttpsURLConnection.setDefaultHostnameVerifier(myHv);
 SSLContext lSC = javax.net.ssl.SSLContext.getInstance("SSL");
 lSC.init(null, trustAll, new java.security.SecureRandom());
 javax.net.ssl.HttpsURLConnection.setDefaultSSLSocketFactory(lSC.getSocketFactory());
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
     

    Fields inherited from interface com.seclore.fs.ws.client.exception.WSClientExceptionConstants

    APPENDER_NOT_CONFIGURED, BASIC_PROTECT_DISABLED, CLIENT_NOT_INITIALIZED, CONTENT_MODIFIES_WO_PERMISSION, DECRYPTED_CONTENT_DIGEST_MISMATCH, DECRYPTED_CONTENT_SIZE_MISMATCH, DIGEST_GENERATE_ERROR, ERROR_RESTORING_FILE, ERROR_TEMP_FILE, FAILED_FETCHING_ORGANIZATION_NAME, FAILED_TO_GENERATE_AES_KEY, FAILED_TO_PARSE_RSA_KEY, FILE_CLOSE_ERR, FILE_EXIST_AT_PROTECTEDFILENAME, FILE_EXIST_AT_UNPROTECTEDFILENAME, FILE_NOT_EXIST, FILE_NOT_SUPPORTED_WRAPPING, FILE_READ_IO_ERROR, FILE_READ_IO_ERROR_WO_NAME, FILE_WRITE_IO_ERROR, FILE_WRITE_IO_ERROR_WO_NAME, FILEEXTINFO_NOT_GIVEN, FILENAME_PROTECTEDFILENAME_ERROR, FS_HELPER_DUPLICATE_IDENTIFIER, FS_HELPER_FAILED_TO_VERIFY_CONFIG_XML, FS_HELPER_FAILED_TO_VERIFY_REQUEST_XML, FS_HELPER_IDENTIFIER_NOT_EXISTS, FS_HELPER_INVALID_INNER_ATTACHMENT_DETAILS, FS_HELPER_INVALID_RESPONSE, FS_HELPER_INVALID_SMAIL, FS_HELPER_MAIL_BODY_DETAILS_NOT_PROVIDED, FS_HELPER_MAIL_DETAILS_NOT_PROVIDED, FS_HELPER_MAIL_SENDER_NOT_PROVIDED, FS_HELPER_MISSING_CRYPTOHANDLER_IMPLEMENTATION, FS_HELPER_NOT_INITIALIZED, FS_HELPER_OBJECT_NOT_INITIALIZED, FS_HELPER_OBJECT_TERMINATED, FS_HELPER_PROTECTED_MAIL_BODY_ATTACHMENT_NOT_PROVIDED, FS_HELPER_RESPONSE_OBJECT_NOT_POPULATED, FS_HELPER_TERMINATE_ERROR, FS_HELPER_TERMINATED, HTML_BACKWARD_COMPATIBILITY_ERROR, HTML_DISPLAY_NAME_CORRUPT, HTML_DISPLAY_NAME_NOT_FOUND, HTML_FORM_DATA_CORRUPT, HTML_INVALID_VERSION_VALUE, HTML_TEMPLATE_CORRUPT, HTML_UNPROTECTED_FILE, HTML_UNWRAP_INVALID_EXT, HTML_WRAP_DISABLED, INVALID_ARRAY, INVALID_BUFFER_FILE_SIZE, INVALID_DECRYPTION, INVALID_ENCRYPTION, INVALID_ENCRYPTION_ALGO_TYPE, INVALID_FILE_SIZE, INVALID_FS_DATE_FORMAT, INVALID_FV, INVALID_HEADER_DIGEST, INVALID_INSTALLATION_PATH, INVALID_KEY, INVALID_POLICY_SERVER_URL, INVALID_VALUE_RECEIVED, INVALID_VALUE_SPECIFIED, INVALID_XML, IO_ERROR, KEY_PARAMETER_REQUIRED, LOADING_LOGGER_CONFIG_ERROR, LOGGER_NOT_CONFIGURED, MANDATORY_PARAMETER_NOT_SPECIFIED, MISSING_FILE, MISSING_LOGGER_PROPERTY_FILE, MISSING_PARAMETER, PROTECTED_FILE_MOVE_FAIL, PROTECTED_WITH_UNKNOWN_PS, PSCONNECTION_OBJECT_NULL, PSCP_CONFIG_INSTANCE_NULL, PSCP_CONFIG_MAX_POOL_SIZE, PSCP_CONNECTION_ALREADY_INITIALIZED, PSCP_CONNECTION_NOT_INITIALIZED_OR_TERMINATED, PSCP_CONNECTION_POOL_CONFIG_NOT_PROVIDED, PSCP_FAILED_TEMINATE_SESSION, PSCP_FAILED_TO_CONNECT, PSCP_FAILED_TO_FETCH_SESSION_ID, PSCP_FAILED_TO_FETCH_SESSION_KEY, PSCP_FAILED_TO_FLUSH_OUTPUT_STREAM, PSCP_FAILED_TO_OPEN_CONNECTION, PSCP_FAILED_TO_OPEN_OUTPUT_STREAM, PSCP_FAILED_TO_PARSE_PING_RESPONSE, PSCP_FAILED_TO_WRITE_DATA_OUTPUT_STREAM, PSCP_HTTP_REQUEST_INFO_IS_NULL, PSCP_INVALID_DEFAULT_SESSION_EXPIRY, PSCP_INVALID_PROXY_DETAILS, PSCP_INVALID_URL, PSCP_LOGIN_FAILED, PSCP_LOGIN_HANDLER_INSTANCE_NULL, PSCP_MISMATCH_ERROR, PSCP_NO_MORE_CONNECTION_AVAILABLE, PSCP_NO_SERVER_URL_PROVIDED, PSCP_POOL_COULD_NOT_INITIALIZE_PS_CONNECTION, PSCP_POOL_TERMINATED, PSCP_RESOURCE_URL_EMPTY_OR_NULL, PSCP_SERVER_DETAILS_IS_NULL, PSCP_UNEXPECTED_ERROR, PSCP_URL_EMPTY_OR_NULL, PSPC_FAILED_TO_CLOSE_RESPONSE_READER, PSPC_FAILED_TO_READ_RESPONSE, PSPC_SESSION_EXPIRED, RESOURCE_MANAGER_NOT_GIVEN, SEC_ERROR_TEMP_FILE, SESSION_KEY_OBJECT_NULL, SYSTEM_EXCEPTION, UNEXPECTED_ERROR, UNPROTECT_FILE_MOVE_FAIL, UNSUPPORTED_ENCODING_UTF_16LE, WSCLIENT_BLACKLISTED_EXTN_VALUE, WSCLIENT_CONFIG_NOT_GIVEN, WSCLIENT_COULD_NOT_DELETE_EXISTING_FILE, WSCLIENT_FWD_VERSION_NOT_SUPPORTED, WSCLIENT_HTML_UNWRAPPING_VERSION_NOT_SUPPORTED, WSCLIENT_HTML_WRAPPING_BUFFER_VERSION_NOT_SUPPORTED, WSCLIENT_HTML_WRAPPING_DATA_VERSION_NOT_SUPPORTED, WSCLIENT_SUPPORTED_EXTN_BASIC_PROTECTION, XML_PARSE_DOCUMENT_ERROR, XML_PARSE_NODE_ERROR, XML_PARSE_VALUE_ERROR

    Fields inherited from interface com.seclore.fs.ws.client.exception.WSExceptionConstants

    EXT_NOT_SUPPORTED, FILECONTENT_MODIFIED, INVALID_FILE, OPEN_EXCLUSIVE_FAIL, PROTECTED_FILE, RESPONSE_ERROR, UNPROTECTED_FILE, WSCLIENT_VERSION_NOT_SUPPORTED
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Returns true if the pool is terminated and all the connections for this pool are also terminated.
    If the pool is terminated but some connections are still in use then this will return false.
     
     
    getPSConnection(boolean pValidate)
    Returns PSConnection from pool, if available.
    boolean
     
    newInstance(String pHSHelperInstanceId, Config pConfig, CryptoHandler pCryptoHandler)
    Returns new object of PSConnectionpool.
    void
    Return a connection back to the pool.
    void
    setLastAccessibleURL(String pLastAccessibleURL)
     
    void
    This method is used to logs the pool status.
    void
    Terminates the entire pool.
    void
     

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Method Details

    • getLastAccessibleURL

      public String getLastAccessibleURL() throws PSCPException
      Returns:
      the lastAccessibleURL
      Throws:
      PSCPException
    • setLastAccessibleURL

      public void setLastAccessibleURL(String pLastAccessibleURL)
      Parameters:
      pLastAccessibleURL - the lastAccessibleURL to set
    • newInstance

      public static PSConnectionPool newInstance(String pHSHelperInstanceId, Config pConfig, CryptoHandler pCryptoHandler)
      Returns new object of PSConnectionpool. After getting the PSConnectionPool instance the application is expected to maintain the same.
      Parameters:
      pHSHelperInstanceId - Helper Instance Id.
      pConfig - The configuration instance.
      pCryptoHandler - CryptoHandler to encrypt and decrypt the protocol for secure communication.
      Returns:
      The PSConnectionPool instance.
    • validateInitialize

      public void validateInitialize() throws PSCPException
      Throws:
      PSCPException
    • getPSConnection

      public PSConnection getPSConnection(boolean pValidate) throws PSCPNoMoreConnectionException, PSCPException
      Returns PSConnection from pool, if available.
      If no connection is available then it will try to make a new authenticated connection till the no of connections does not exceed Max size specified.
      In such a scenario, it will throw PSCPNoMoreConnectionException.
      If it is unable to create a new authenticated connection with any of the URLs specified then it will throw PSCPException with appropriate error code depicting the same.
      Parameters:
      pValidate - Validate flag for PSConnection. If this flag is true then PSConnection will be validated before returning it. This is done by firing a PING request to the server. It checks that the session is valid and the user is logged in. You will not get a invalid / broken connection if this flag is set to true. However, there is a slight overhead of firing a PING request everytime.
      Returns:
      The PSConnection instance which contains the session id generated by server.
      Throws:
      PSCPException - The PSCPException instance.
      PSCPNoMoreConnectionException
    • releasePSConnection

      public void releasePSConnection(PSConnection pPSConnection)
      Return a connection back to the pool. User will typically call this method when the connection is no longer required.
      Note : If the Pool is terminated by some means, the pool will not going to hold any released connections.In that case, the Connections will be Garbage Collected by JVM.
      Parameters:
      pPSConnection - The PSConnection instance to be released.
      Throws:
      PSCPException - PSCPException instance in case of any error during releasing the connection.
    • terminate

      public void terminate() throws PSCPException
      Terminates the entire pool. This will close all the connections.
      Once a pool is terminated, one can not get a new connection from this pool.
      Connections which are in use will get terminated when they are released back to the pool.
      Throws:
      PSCPException - The PSCPException instance if any error during the terminate.
    • canDestroy

      public boolean canDestroy()
      Returns true if the pool is terminated and all the connections for this pool are also terminated.
      If the pool is terminated but some connections are still in use then this will return false.
      Returns:
      True if all the connections in the pool are terminated, False otherwise.
    • status

      public void status()
      This method is used to logs the pool status.
    • getId

      public String getId()
    • isPooledConnection

      public boolean isPooledConnection(PSConnection pPSConnection)